home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Internet / opo.akua.ch Update < prev    next >
Encoding:
Text File  |  1999-03-04  |  5.4 KB  |  266 lines  |  [TEXT/ToyS]

  1. property kasRemoteURL : "ftp://opo:opo@opo.akua.ch"
  2. -- property kasRemoteURL : "ftp://opo:opo@11.9.0.20"
  3. property kasRemotePath : "/"
  4. property kasLocalPath : ":OPO:"
  5.  
  6.  
  7. property kasPrefName : (kasRemoteURL & " >> " & kasRemotePath)
  8.  
  9. global gasToSync, gasLastUpdate
  10. global gasInfo, gasInfoPos
  11. global gasUpFile, gasUpFold, gasRmFile, gasRmFold
  12.  
  13.  
  14. on run
  15.     set thisDate to current date
  16.     pfLoad()
  17.     
  18.     set gasUpFile to 0
  19.     set gasUpFold to 0
  20.     set gasRmFile to 0
  21.     set gasRmFold to 0
  22.     
  23.     set gasInfo to display info titled ((kasLocalPath as string) & " => " & kasRemotePath) ¬
  24.         message ("Host: " & kasRemoteURL) ¬
  25.         located at gasInfoPos
  26.     
  27.     set gasToSync to {{kasRemotePath, kasLocalPath}}
  28.     
  29.     ShowAction("Connecting")
  30.     tell application "Fetch" to activate
  31.     pause for 60
  32.     tell application "Fetch"
  33.         geturl kasRemoteURL
  34.         set tw to transfer window 1
  35.     end tell
  36.     pause for 60
  37.     activate
  38.     
  39.     repeat while gasToSync is not {}
  40.         display info gasInfo ¬
  41.             message ("Folders to go: " & (the number of items in gasToSync)) ¬
  42.             at line 10
  43.         -- Fifo list
  44.         set iSync to item 1 of gasToSync
  45.         if (number of items of gasToSync) is 1 then
  46.             set gasToSync to {}
  47.         else
  48.             set gasToSync to items 2 thru -1 of gasToSync
  49.         end if
  50.         
  51.         set lPath to (item 2 of iSync) as string
  52.         set rPath to item 1 of iSync
  53.         
  54.         ShowRemote(rPath)
  55.         ShowLocal(lPath)
  56.         
  57.         set tw to UpNewer(tw, lPath, rPath, gasLastUpdate)
  58.     end repeat
  59.     
  60.     tell application "Fetch"
  61.         activate
  62.         ignoring application responses
  63.             close tw
  64.         end ignoring
  65.     end tell
  66.     
  67.     activate
  68.     
  69.     set gasInfoPos to screen location of ¬
  70.         (display info gasInfo with disposal)
  71.     
  72.     set gasLastUpdate to thisDate
  73.     pfSave()
  74. end run
  75.  
  76.  
  77. on UpNewer(tw, lPath, rPath, lastUpdate)
  78.     ShowAction("Checking for updated files…")
  79.     set lList to LocalListNewer(lPath, lastUpdate)
  80.     
  81.     -- Scan for local files in remote list    
  82.     ShowAction("Uploading updated files…")
  83.     set uploadedOne to false
  84.     set lFiles to item 1 of lList
  85.     
  86.     repeat with lName in lFiles
  87.         ShowFile(lName)
  88.         
  89.         -- Upload missing file?
  90.         if (not uploadedOne) then
  91.             set tw to FetchDirSet(tw, rPath)
  92.             set uploadedOne to true
  93.         end if
  94.         
  95.         ShowAction("Uploading")
  96.         FetchUL(tw, (lPath & lName) as alias, rPath)
  97.         ShowFileCnt()
  98.     end repeat
  99.     
  100.     -- Check directories, queue local to sync
  101.     ShowAction("Queuing Folders…")
  102.     
  103.     set lDirs to item 2 of lList
  104.     repeat with ld in lDirs
  105.         -- Check for remote existance
  106.         ShowFile(ld)
  107.         set gasToSync to gasToSync & {{rPath & ld & "/", (lPath & ld) as alias}}
  108.     end repeat
  109.     
  110.     return tw
  111. end UpNewer
  112.  
  113.  
  114. on FetchUL(tw, lAlias, rPath)
  115.     try
  116.         with timeout of 60 seconds
  117.             tell application "Fetch" to ¬
  118.                 put into tw item lAlias ¬
  119.                     text format text binary format Raw Data
  120.         end timeout
  121.     on error
  122.         set tw to FetchDirSet(tw, rPath)
  123.         with timeout of 60 seconds
  124.             try
  125.                 tell application "Fetch" to ¬
  126.                     put into tw item lAlias ¬
  127.                         text format text binary format Raw Data
  128.             on error
  129.                 return FetchUL(tw, lAlias, rPath)
  130.             end try
  131.         end timeout
  132.     end try
  133.     
  134.     return tw
  135. end FetchUL
  136.  
  137.  
  138. on LocalListNewer(pathAlias, newerThan)
  139.     ShowAction("Local Listing")
  140.     
  141.     set fList to the entries in pathAlias ¬
  142.         whose kinds are a file ¬
  143.         who were modified after newerThan
  144.     
  145.     set pList to the entries in pathAlias ¬
  146.         whose kinds are a folder
  147.     
  148.     return {fList, pList}
  149. end LocalListNewer
  150.  
  151.  
  152. on FetchDirSet(tw, vpath)
  153.     ShowAction("Remote CD")
  154.     
  155.     try
  156.         with timeout of 60 seconds
  157.             tell application "Fetch" to ¬
  158.                 set current directory of tw to vpath
  159.         end timeout
  160.         pause for 30
  161.     on error err
  162.         ShowAction("Reconnect…")
  163.         with timeout of 300 seconds
  164.             tell application "Fetch"
  165.                 activate
  166.                 close tw
  167.             end tell
  168.         end timeout
  169.         pause for 30
  170.         try
  171.             with timeout of 60 seconds
  172.                 tell application "Fetch"
  173.                     activate
  174.                     geturl kasRemoteURL
  175.                     set tw to transfer window 1
  176.                 end tell
  177.             end timeout
  178.             pause for 30
  179.             with timeout of 60 seconds
  180.                 tell application "Fetch"
  181.                     activate
  182.                     set current directory of tw to vpath
  183.                 end tell
  184.             end timeout
  185.             activate
  186.         on error err
  187.             activate
  188.             -- display dialog ("Connection Lost?" & return & return & "(" & err & ")") ¬
  189.             -- buttons {"Cancel", "OK"} default button 2 with icon stop
  190.             set tw to FetchDirSet(tw, vpath)
  191.         end try
  192.     end try
  193.     
  194.     return tw
  195. end FetchDirSet
  196.  
  197.  
  198. on ShowAction(msg)
  199.     display info gasInfo ¬
  200.         message msg ¬
  201.         at line 15 ¬
  202.         using color 15
  203. end ShowAction
  204.  
  205.  
  206. on ShowRemote(msg)
  207.     display info gasInfo ¬
  208.         message msg ¬
  209.         at line 5 ¬
  210.         using color 10 * 32
  211. end ShowRemote
  212.  
  213.  
  214. on ShowLocal(msg)
  215.     display info gasInfo ¬
  216.         message msg ¬
  217.         at line 4 ¬
  218.         using color 10 * 32
  219. end ShowLocal
  220.  
  221.  
  222. on ShowFile(msg)
  223.     display info gasInfo ¬
  224.         message msg ¬
  225.         at line 6 ¬
  226.         using color (10 * 32 + 10) ¬
  227.         with a change of style
  228. end ShowFile
  229.  
  230.  
  231. on ShowFileCnt()
  232.     set gasUpFile to gasUpFile + 1
  233.     display info gasInfo ¬
  234.         message ("Uploaded " & gasUpFile & " file(s)") ¬
  235.         at line 13 ¬
  236.         using color (10 * 1024 + 10 * 32)
  237. end ShowFileCnt
  238.  
  239.  
  240. on ShowFoldCnt()
  241.     set gasUpFold to gasUpFold + 1
  242.     display info gasInfo ¬
  243.         message ("Uploaded " & gasUpFold & " folder(s)") ¬
  244.         at line 14 ¬
  245.         using color (10 * 1024 + 10 * 32)
  246. end ShowFoldCnt
  247.  
  248.  
  249. on pfLoad()
  250.     try
  251.         set ourPrefs to (load preference named kasPrefName)
  252.         set gasInfoPos to item 1 of ourPrefs
  253.         set gasLastUpdate to item 2 of ourPrefs
  254.     on error
  255.         set gasInfoPos to {-1, -1}
  256.         set gasLastUpdate to current date
  257.         pfSave()
  258.         display dialog "First run, time marked!" buttons {"Cancel"} default button 1
  259.     end try
  260. end pfLoad
  261.  
  262.  
  263. on pfSave()
  264.     save preference {gasInfoPos, gasLastUpdate} named kasPrefName
  265. end pfSave
  266.